package com.teach.order.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.common.bean.PageVo;
import com.common.bean.QueryCondition;
import com.common.bean.Response;
import com.teach.dto.OrderFoods;
import com.teach.order.model.dto.OrderDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.teach.order.impl.OrdersServiceImpl;
import com.teach.order.model.po.Orders;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-03-10
 */
@RestController
@RequestMapping("/orders")
public class OrdersController {
    @Autowired
    private OrdersServiceImpl serviceOrders;

    @RequestMapping("/index")
    public String fun(HttpServletRequest request,HttpServletResponse response){
        return "ok";
    }
    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @RequestMapping("/list")
    public Response<PageVo> getList(@RequestParam(value = "associatorId",required = false)String associatorId, QueryCondition queryCondition){
        QueryWrapper<Orders> ordersQueryWrapper=new QueryWrapper<Orders> ();
        ordersQueryWrapper.eq("operator_id",associatorId);
        PageVo page = serviceOrders.queryPage(queryCondition,ordersQueryWrapper);
        return Response.ok(page);
    }
    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @GetMapping("/info")
    public Response<Orders> info(@RequestParam("entity") Orders entity){
		Orders info = serviceOrders.getById(entity.getId());
        return Response.ok(info);
    }
    @ApiOperation("下单")
    @PostMapping("/add")
    public Response<Object> add(@RequestBody(required = true) OrderDTO entity){
        serviceOrders.add(entity);
        return Response.ok(null);
    }
}

